'''
Created on Mar 18, 2013

@author: kevinbauer
'''
import sys

import numpy as np
import time
import pickle
from TrainingData import TrainingData
from TestingData import TestingData
from RecurrentNeural import Recurrent
from Network import Network
from ConstantObj import ConstantObj
from ResultAnalysis import ResultAnalysis




print "start----------"
'''
Traing data and test data from KDD Cup 1999 Data Set
'''
trainingFile = 'D:/NDSU/Project/neural/kddcup.data_10_percent.txt'
testFile = 'D:/NDSU/Project/neural/corrected/corrected.txt'
starttime = time.clock()  

training = TrainingData(trainingFile)

endtime = time.clock() 
print "reading time used:",(endtime-starttime)

recurrent = Recurrent();
network = Network();
resultAnalysis = ResultAnalysis()

normalData = recurrent.normalize(training.training)

print " input data shape is:", np.array(normalData).shape

#network = recurrent.perceptionLearning(normalData,network)



#
network = recurrent.BackPropLearing(normalData,network,1000,5,4)

inputLayerWeightArr = network.getInputLayerWeightArr()
hiddenLayerWeight = network.gethiddenWeightArr()


np.save("tt.npy", inputLayerWeightArr)

kk = np.load("tt.npy")
# mydb  = open('inputLayerWeightArr', 'w')
# pickle.dump(inputLayerWeightArr, mydb)
# 
# mydb1  = open('hiddenLayerWeight', 'w')
# pickle.dump(hiddenLayerWeight, mydb1)
# 
# # network.printWeightData()
# 
# networkObj  = open('inputLayerWeightArr', 'r')  
# inputLayerWeightArr2 = pickle.load(networkObj) 


testing = TestingData(testFile)

print "testing data shape:",testing.testing.shape




testData = recurrent.normalize(testing.testing)

subTestData = testData[:400000] 


#testResult = recurrent.testData(testData,network)
testResult = recurrent.testDataByBackProp(subTestData,network,400000)


print "test result shape",testResult.shape

errLineNum = resultAnalysis.compareResult(testResult)


#testing.printData()